#include "mainwindow.h"
#include <QApplication>
#include <QXmlStreamReader>
#include <QDebug>
#include <QBuffer>
#include <QDir>
#include "loader.h"
#include "window.h"
#include "button.h"
#include "virtualpaintengine.h"
#include "windowmanager.h"

const char import[] = "<Label x=\"10\" y=\"10\" key=\"522\"/>";

const char xml[] =\
"<Page>"\
    "<Import>"\
        "<Element name=\"F1\" src=\"f1.xml\"/>"\
        "<Element name=\"F2\" src=\"f1.xml\"/>"\
        "<Element name=\"F3\" src=\"f1.xml\"/>"\
    "</Import>"\
    "<Window id=\"2\" name=\"window\" x=\"1\" y=\"2\">"\
            "<Label name=\"l1\" x=\"1\" y=\"1\" text=\"标签1\" color=\"123\"/>"\
            "<Label name=\"l2\" x=\"{{l1.x+5}}\" y=\"{{l1.y}}\" text=\"标签2\"/>"\
            "<F1 name=\"F1\" text=\"中文\"/>"\
            "<F2 text=\"F2\" y=\"11\"/>"\
            "<F3 text=\"F3\" y=\"12\"/>"\
    "</Window>"\
"<Page/>";

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    PaintDevice::setPaintEngine(new VirtualPaintEngine());
    WindowManager wm;
    Loader loader;
//    QXmlStreamReader reader(impolrt);
//    loader.loadXML(reader, "f1.xml");
//    reader.clear();
//    reader.addData(xml);

    Element *e2 = loader.loadXML("uitest/配接信息.xml");
    Q_ASSERT(e2);
    wm.addWindow(qobject_cast<Window*>(e2));

    Element *e = loader.loadXML("uitest/HTP全局.xml");
    Q_ASSERT(e);
    qDebug() << e->name() << e->x() << e->y();
    Window *w = qobject_cast<Window*>(e);
    wm.addWindow(w);
    wm.switchWindowTo(1);
    e = w->element("f5");
    Q_ASSERT(e);
    Button *b = qobject_cast<Button*>(e);
    Q_ASSERT(b);
    wm.onKeyboardEvent(537, 1);
//    qDebug() << e->name() << e->x() << e->y();
//    e = w->element("l2");
//    Q_ASSERT(e);
//    qDebug() << e->name() << e->x() << e->y();
//    for(int k:e->bindingKeys()){
//        qDebug() << k;
//    }

//    e->hide();
//    e->update();
    return a.exec();
}
